<template>
    <div>


        <mt-swipe :auto="4000">
                <mt-swipe-item>1</mt-swipe-item>
                <mt-swipe-item>2</mt-swipe-item>
                <mt-swipe-item>3</mt-swipe-item>
            </mt-swipe>
        <div class="goodsWrap">
            <div class="u-flex u-row-between">
                <div>
                    <span class="u-font-36 u-font-bold">经典游记</span>
                </div>
            </div>




            <div class="scroll-wrapper" ref="trlScroll">
                <div class="scroll-content">
                    <div class="trlList" v-for="item in travelList" :key="item.id" @click="goDetail(item.id)">
                        <div class="scroll-card">
                            <div>
                                <div>
                                    <img :src="baseUrl + item.cover" class="scroll-card-cover" mode="scaleToFill" />
                                </div>
                                <div>
                                    <span class="u-font-30">{{ item.title }}</span>
                                </div>
                                <div>
                                    <span class="u-font-20">{{ item.goodNum }}赞</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


            <div class="u-flex u-row-between u-margin-top-20">
                <div>
                    <span class="u-font-36 u-font-bold">热门笔记</span>
                </div>
            </div>
            <div class="scroll-wrapper" ref="trlScroll">
                <div class="scroll-content">
                    <div class="trlList" v-for="item in travelList" :key="item.id" @click="goDetail(item.id)">
                        <div class="scroll-card">
                            <div>
                                <div>
                                    <img :src="baseUrl + item.cover" class="scroll-card-cover" mode="scaleToFill" />
                                </div>
                                <div>
                                    <span class="u-font-30">{{ item.title }}</span>
                                </div>
                                <div>
                                    <span class="u-font-20">{{ item.goodNum }}赞</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


            <div class="u-flex u-row-between u-margin-top-20">
                <div>
                    <span class="u-font-36 u-font-bold">当季旅游攻略</span>
                </div>
            </div>
        </div>

        <cmt-footer />
    </div>
</template>

<script>
import { Swipe, SwipeItem } from 'mint-ui';

import cmtFooter from '@/components/footer'
import BScroll from 'better-scroll';
export default {
    components: {
        cmtFooter,
        Swipe,
        SwipeItem

    },
    data() {
        return {
            searchValue: '',
            travelList: [],
            advList: [],
            baseUrl: 'http://172.31.1.104:9090'
        }
    },
    mounted() {
        this.isLogin();
        this.getAdv()
    }, 
    methods: {
        isLogin() {
            if (!this.$store.state.isLogin) {
                this.$router.push('/login');
            } else {
                this.getArticleList();
            }
        },
        getArticleList() {
            this.$axios({
                url: this.$api.getArticleList,
                method: 'get',
                params: {
                    pageNum: 1,
                    pageSize: 10,
                    category: '2'
                }
            }).then(res => {
                this.travelList = res.rows;
                this.$nextTick(() => {
                    this.bs = new BScroll(this.$refs.trlScroll, {
                        scrollX: true,
                        click: true,
                        probeType: 3 // listening scroll event
                    });
                })
            })
        },
        goDetail(id) {
            this.$router.push({ path: '/detail', query: { id: id } })
        },
        getAdv() {
            this.$axios({
                url: this.$api.getAdv,
                method: 'get'
            }).then(res => {
                this.advList = res.data
                // console.log(res);
            })
        }
    }
}
</script>

<style lang="scss" scoped>
.searchBox {
    width: 100%;
    height: 44px;
    overflow: hidden;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 7;
}

.goodsWrap {
    width: 100%;
    padding: 10px 15px;
}

.scroll-wrapper {
    position: relative;
    width: 100%;
    margin: 0 auto;
    white-space: nowrap;
    border-radius: 5px;
    overflow: hidden;

    .scroll-content {
        display: inline-block;
        padding: 5px 0;
    }

    .trlList {
        display: inline-block;
    }

    .scroll-card {
        display: inline-block;
        width: 250px;
        height: 130px;
        margin-right: 10px;
        text-align: left;

        img {
            border-radius: 5px;
        }

        .scroll-card-cover {
            height: 130px;
            width: 100%;
        }
    }
}

.advImg {
    width: 40px;
    height: 40px;
}
</style>